<%--
  @desc: 新闻栏目列表
  @author: chenw
  @create: 2014-4-29 下午 15:32
--%>
<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<div class="pageHeader">
    <form rel="pageForm" onsubmit="return navTabSearch(this);" action="<c:url value='/news/index'/>" method="post">
        <div class="searchBar">
            <ul>
                <li style="float: left;line-height: 25px;">
                    <label style="width:80px;">关键字搜索：</label>
                    <input name="keywords" type="text" value="${query.keywords}" placeholder="请输入关键字检索"
                           style="width:250px;font-family:'微软雅黑 sans-serif serif';"/>
                </li>
                <li style="float: left; line-height: 25px;">
                    <label style="width:80px;">发布时间：</label>
                    <input name="start" type="text"
                            class="date" datefmt="yyyy-MM-dd HH:mm:ss"
                            value="<fmt:formatDate value="${query.start}" pattern="yyyy-MM-dd HH:mm:ss"/>"
                            placeholder="起始时间"
                            style="width: 100px; font-family: '微软雅黑 sans-serif serif';"/> - <input
                        name="end" type="text" class="date" datefmt="yyyy-MM-dd HH:mm:ss"
                        value="<fmt:formatDate value="${query.end}" pattern="yyyy-MM-dd HH:mm:ss"/>"
                        placeholder="结束时间"
                        style="width: 100px; font-family: '微软雅黑 sans-serif serif';"/>
                </li>
                <%--<li style="float: left; line-height: 25px;">
                    <label style="width:60px;">新闻栏目：</label>
                	<select id="txt_news_channel" name="handler" class="combox">
	                	<option value="">-请选择-</option>
	                	<option value="1">警方提示</option>
	                	<option value="2">安全知识</option>
	                	<option value="3">公示公告</option>
	                	<option value="4">警方报道</option>
                	</select>
                </li>--%>
                <li>
                    <div class="buttonActive" style="margin-left: 5px;">
                        <div class="buttonContent">
                            <button type="submit">查找</button>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </form>
</div>
<div class="pageContent" style="padding-top: 1px;">
    <div class="panelBar">
        <ul class="toolBar">
            <li><a href="<c:url value='/news/gotoNews/0'/>" target="dialog" width="800" height="500" mask="true" resizable="false" maxable="false"  class="add" rel="page_news_add" title="新增新闻"><span>新增</span></a></li>
            <li><a href="<c:url value='/news/delete/{sel_id}'/>" target="ajaxDel" class="delete" title="确定要删除吗?"><span>删除</span></a></li>
            <li><a href="<c:url value='/news/gotoNews/{sel_id}'/>" target="dialog" width="800" height="500" mask="true" resizable="false" maxable="false"  class="add" rel="page_news_edit" title="编辑新闻"><span>编辑</span></a></li>
			<li><a href="javascript:beforePublish();" class="add" ><span>发布</span></a></li>
            <li><a href="<c:url value='/news/viewNews/{sel_id}'/>" target="dialog" width="400" height="520" mask="true" resizable="true" maxable="false"  class="edit" rel="page_news_detail" title="新闻预览"><span>预览</span></a></li>
            <li class="line">line</li>
        </ul>
    </div>
    <table nowrapTD="false" class="table" width="100%" layoutH="115">
        <thead>
        <tr>
            <th width="40" align="center">序号</th>
            <th width="40" align="center">新闻标题</th>
            <th width="70" align="center">新闻概述</th>
            <th width="40" align="center">发布人</th>
            <th width="40" align="center">新闻栏目</th>
            <th width="50" align="center">新闻源</th>
            <th width="40" align="center">发布时间</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="news" items="${pager.list}" varStatus="vs">
            <tr target="sel_id" rel="${news.id}">
                <td>${vs.count+(pager.pageNum-1)*pager.numPerPage}</td>
                <td>${news.title}</td>
                <td>${news.summary}</td>
                <td>${news.author}</td>
                <c:choose>
                	<c:when test="${news.channelId == 1}"><td>警方提示</td></c:when>
                	<c:when test="${news.channelId == 2}"><td>安全知识</td></c:when>
                	<c:when test="${news.channelId == 3}"><td>公示公告</td></c:when>
                	<c:otherwise><td>警务报道</td></c:otherwise>
                </c:choose>
                <c:choose>
                    <c:when test="${news.pubDept == 'app后台' or news.pubDept == 'app后台_V2'}">
                        <td>${news.pubDept}</td>
                    </c:when>
                	<c:otherwise><td>网上公安后台</td></c:otherwise>
                </c:choose>
                <c:choose>
                	<c:when test="${empty news.pubTime}">
                		<td>未发布</td>
                	</c:when>
                	<c:otherwise>
		                <td><fmt:formatDate value="${news.pubTime}" pattern="yyyy-MM-dd HH:mm"/></td>
                	</c:otherwise>
                </c:choose>
                <input type="hidden" id="news${news.id}" value="${news.pubTime}">
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <div class="panelBar">
        <div class="pages">
            <span>显示&nbsp;</span>
            <select id="cob_ps" class="combox" name="numPerPage" onchange="navTabPageBreak({numPerPage:this.value})">
                <option value="20">20</option>
                <option value="50">50</option>
                <option value="100">100</option>
                <option value="200">200</option>
            </select>
            <span>条，共${pager.total}条</span>
        </div>
        <div class="pagination" targetType="navTab" totalCount="${pager.total}" numPerPage="${pager.numPerPage}" pageNumShown="10"
             currentPage="${pager.pageNum}"></div>
    </div>
    <form id="pagerForm" method="post" action="<c:url value='/news/index'/>">
        <input type="hidden" name="pageNum" value="${pager.pageNum}"/>
        <input type="hidden" name="keywords" value="${query.keywords}"/>
        <input type="hidden" name="numPerPage" value="${pager.numPerPage}"/>
        <input type="hidden" name="handler" value="${query.handler}"/>
        <input type="hidden" name="start" value="<fmt:formatDate value="${query.start}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
        <input type="hidden" name="end" value="<fmt:formatDate value="${query.end}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
    </form>
</div>
<script type="text/javascript">
$(function (){
	$("#txt_news_channel").val("${query.handler}");
});
function beforePublish(){
	//隐藏表单是否有值来判断是否发布
    if(typeof(sel_id) == "undefined"){
        alertMsg.info("请选择待发布新闻");
        return;
    }
    var id = sel_id.value;

	if($("#news"+id).val()==""){
		alertMsg.confirm("是否发布？",{
			okCall: function(){
				$.ajax({
	                url: "<c:url value='/news/pubNews/"+id+"'/>",
	                type: "get",
	                success: function (resp, status, xhr) {
	                	alertMsg.info(resp.msg);
	                	navTab.reloadFlag("page_news_list");
	                }
	            });
			}
		});
	}else{
		alertMsg.info("新闻已经发布");
	}
}
</script>